using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QLNhaSach.BUS.DTO;
using QLNhaSach.BUS;

namespace QLNhaSach.GUI.NhanVienKeToan
{
    public partial class XuatPhieuThu : Form
    {
        DataTable dt = new DataTable();
        CR2_XuatPhieuThu report2 = new CR2_XuatPhieuThu();
        public NhanVienDTO nv = new NhanVienDTO();

        public XuatPhieuThu()
        {
            InitializeComponent();
        }

        private void ClearForm()
        {
            txtMaKH.Clear();
            txtHoTen.Clear();
            txtDiaChi.Clear();
            txtDienThoai.Clear();
            txtSoTien.Clear();
            dtiNgayLap.ResetValue();
            txtMaKH.Focus();
        }

        private void ShowReport()
        {
            report2.SetParameterValue("ma", txtMaKH.Text);
            report2.SetParameterValue("hoten", txtHoTen.Text);
            report2.SetParameterValue("diachi", txtDiaChi.Text);
            report2.SetParameterValue("dienthoai", txtDienThoai.Text);
            report2.SetParameterValue("sotien", txtSoTien.Text);
            report2.SetParameterValue("ngaylap", dtiNgayLap.Value);
            report2.SetParameterValue("nguoitao",nv.HoTen);

            CrystalDecisions.Shared.TableLogOnInfo tli = new CrystalDecisions.Shared.TableLogOnInfo();
            foreach (CrystalDecisions.CrystalReports.Engine.Table tb in report2.Database.Tables)
            {
                tli = tb.LogOnInfo;
                tli.ConnectionInfo.ServerName = Application.StartupPath + "\\QLNhaSach.mdb";
                tb.ApplyLogOnInfo(tli);
            }

            crystalReportViewer1.ReportSource = report2;

        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            ClearForm();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            if (txtMaKH.Text != "" && txtHoTen.Text != "" && txtSoTien.Text != ""
                && txtDiaChi.Text != "" && txtDienThoai.Text != ""
                && txtSoTien.Text != "" && !dtiNgayLap.IsEmpty)
            {
                ShowReport();
                ClearForm();
            }
            else
            {
                MessageBox.Show("Thong Tin Nhap Khong Day Du, Moi Nhap Lai !!");
                ClearForm();
            }
        }

        private void XuatPhieuThu_Load(object sender, EventArgs e)
        {
            dt = NhanVienKeToanBUS.HienThiTTCN(nv);
            nv.HoTen = dt.Rows[0][1].ToString();
        }
    }
}